<?php
/**
 * featured_products module - prepares content for display
 *
 * @package modules
 * @copyright Copyright 2003-2007 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: featured_products.php 6424 2007-05-31 05:59:21Z ajeh $
 */
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}

// initialize vars
$categories_products_id_list = '';
$list_of_products = '';
$guitar_featured_products_query = '';
$display_limit = '';

$category_id =3;

if ( (($manufacturers_id > 0 && $_GET['filter_id'] == 0) || $_GET['music_genre_id'] > 0 || $_GET['record_company_id'] > 0) || (!isset($new_products_category_id) || $new_products_category_id == '0') ) {
  $guitar_featured_products_query = "select distinct p.products_id, p.products_image, pd.products_name, p.master_categories_id
                           from " . TABLE_PRODUCTS . " p
                          	left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id 
                            where p.products_id = pd.products_id
                           and p.master_categories_id = ".$category_id."
                           and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'";
} else {
  // get all products and cPaths in this subcat tree
  $productsInCategory = zen_get_categories_products_list( (($manufacturers_id > 0 && $_GET['filter_id'] > 0) ? zen_get_generated_category_path_rev($_GET['filter_id']) : $cPath), false, true, 0, $display_limit);

  if (is_array($productsInCategory) && sizeof($productsInCategory) > 0) {
    // build products-list string to insert into SQL query
    foreach($productsInCategory as $key => $value) {
      $list_of_products .= $key . ', ';
    }
    $list_of_products = substr($list_of_products, 0, -2); // remove trailing comma
    $guitar_featured_products_query = "select distinct p.products_id, p.products_image, pd.products_name, p.master_categories_id
                                from " . TABLE_PRODUCTS . " p
                                left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id
                                where  p.products_id = pd.products_id
                                and p.master_categories_id = ".$category_id."
                                and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
                                and p.products_id in (" . $list_of_products . ")";
  }
}
if ($guitar_featured_products_query != '') $guitar_products = $db->ExecuteRandomMulti($guitar_featured_products_query, MAX_DISPLAY_SEARCH_RESULTS_FEATURED);

$row = 0;
$col = 0;
$guitar_box_contents = array();
$title = '';

$num_products_count = ($guitar_products == '') ? 0 : $guitar_products->RecordCount();

// show only when 1 or more
if ($num_products_count > 0) {
  if ($num_products_count < SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS || SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS == 0) {
    $col_width = floor(100/$num_products_count);
  } else {
    $col_width = floor(100/SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS);
  }
  while (!$guitar_products->EOF) {

    //这里需要自定义一下显示价格的函数．
    $products_price = zen_get_products_display_price_main($guitar_products->fields['products_id']);
    
    if (!isset($productsInCategory[$guitar_products->fields['products_id']])) $productsInCategory[$guitar_products->fields['products_id']] = zen_get_generated_category_path_rev($guitar_products->fields['master_categories_id']);

    
    if($guitar_products->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0){
        $image_link = "";
        $product_image = "";
    }else{
        $image_link = ($guitar_products->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ?  '' : zen_href_link(zen_get_info_page($guitar_products->fields['products_id']), 'cPath=' . $productsInCategory[$guitar_products->fields['products_id']] . '&products_id=' . $guitar_products->fields['products_id']);
        $product_image = zen_image(DIR_WS_IMAGES . $guitar_products->fields['products_image'], $guitar_products->fields['products_name'], IMAGE_FEATURED_PRODUCTS_LISTING_WIDTH, IMAGE_FEATURED_PRODUCTS_LISTING_HEIGHT) ;
    
    }
    
    $product_link = zen_href_link(zen_get_info_page($guitar_products->fields['products_id']), 'cPath=' . $productsInCategory[$guitar_products->fields['products_id']] . '&products_id=' . $guitar_products->fields['products_id']);
    $product_name = $guitar_products->fields['products_name'] ;
    
    //$list_box_contents[$row][$col] = array('params' =>'class="centerBoxContentsFeatured centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
    //$list_box_contents[$row][$col] = array('params' =>'class="man_index_pic centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
   // 										'text' => (($guitar_products->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ? '' : '<a href="' . $image_link . '">' . $product_image. '</a><br />') 
    //                                                . '<a href="' . $product_link . '">' . $product_name . '</a><br />' . $products_price);
    $guitar_box_contents[$row][$col] = array('params' =>'class="single"',
    										'text' => 
                                            		'<div class="thumb"><a href="'.$image_link.'">'.$product_image.'</a>
                                                        '. $products_price["price"] .'
                                                    </div>
                                                    <div class="info">
                                                    	<div class="name"><a href="'. $product_link .'">'. $product_name .'</a></div>
                                                    	'.$products_price["ref_price"].'
                                                    </div>');
                                                
    $col ++;
    if ($col > (SHOW_PRODUCT_INFO_COLUMNS_FEATURED_PRODUCTS - 1)) {
      $col = 0;
      $row ++;
    }
    $guitar_products->MoveNextRandom();
  }
  
  if ($guitar_products->RecordCount() > 0) {
    if (isset($new_products_category_id) && $new_products_category_id !=0) {
      $category_title = zen_get_categories_name((int)$new_products_category_id);
      $title = '<h2 class="centerBoxHeading">' . TABLE_HEADING_MAN_PRODUCTS . ($category_title != '' ? ' - ' . $category_title : '') . '</h2>';
    } else {
      //$title = '<h2 class="centerBoxHeading">' . TABLE_HEADING_MAN_PRODUCTS . '</h2>';
      $title = '<h2 class="centerBoxHeading"><div style="float:left" >' . TABLE_HEADING_MAN_PRODUCTS . '</div> ' . "<div id='main_subcat'> | 男装 | 皮鞋 | 更多</div>" . "<div class='produce_show_more float-right'>显示更多</div>" . '</h2>' ;	//!!!!
     
    }
    $title = $title . "<div id='man_catalog_bk'></div>";
    $zc_show_featured = true;
  }
}
?>